import axios from "axios";

class Http {
  // constructor 是一种用于创建和初始化class创建的对象的特殊方法。
  constructor(opts = {}) {
    opts.timeout = opts.timeout || 5000;
    //   添加到成员属性
    this.opts = opts;
  }

  // 返回一个axios的实例对象
  getTnstence(opts = {}) {
    //   对象合并  深拷贝
    let options = { ...this.opts, ...opts };
    return axios.create(options);
    // let options = Object.assign({},this.opts,opts)
  }

  get(url) {
    return this.getTnstence().get(url);
  }
  post(url, data = {}) {
    return this.getTnstence().post(url, data);
  }
}

export default new Http();
